/*
 * Copyright 2012 Fabian Wenzelmann
 * 
 * This file is part of Recognition-Procedures-for-Boolean-Functions.
 * 
 * Recognition-Procedures-for-Boolean-Functions is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Recognition-Procedures-for-Boolean-Functions is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Recognition-Procedures-for-Boolean-Functions.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.wenzelmf.booleanFunction.booleanExpression;

import java.util.HashSet;
import java.util.Set;

import de.wenzelmf.booleanFunction.lpb.util.LPBCombinatorialConstants;

/**
 * An implementation of {@link Assignment} that stores a list of all variables that are
 * made <i>true</i> by this assignment.
 * 
 * @author Fabian Wenzelmann
 * @version 1.0
 *
 */
public class SimpleAssignment implements Assignment
{

	/*
	 * The set of true variables.
	 */
	private HashSet<String> trueVariables;
	
	/**
	 * Creates a new assignment were all variables are mapped to <i>false</i>.
	 */
	public SimpleAssignment()
	{
		this.trueVariables = new HashSet<String>();
	}
	
	/**
	 * Creates a new assignment where all variables are mapped to <i>false</i> given an
	 * initial capacity for the set.
	 */
	public SimpleAssignment(int initialCapacity)
	{
		this.trueVariables = new HashSet<String>((int)(initialCapacity * LPBCombinatorialConstants.HASH_SIZE_FACTOR));
	}
	
	/**
	 * Creates a new assignment where the <i>true</i> variables are given as a set.
	 *  
	 * @param trueVariables The set of all variables this assignment assigns <i>true</i> to.
	 */
	public SimpleAssignment(Set<String> trueVariables)
	{
		this.trueVariables = new HashSet<String>(trueVariables);
	}
	
	@Override
	public boolean getTruthValue(Atom a)
	{
		return trueVariables.contains(a.getIdentifier());
	}
	
	/**
	 * Adds a variable to the <i>true</i> set.
	 * 
	 * @param atomIdentifer The identifier of the variable.
	 */
	public void makeTrue(String atomIdentifer)
	{
		trueVariables.add(atomIdentifer);
	}
	
	/**
	 * Removes a variable from the <i>true</i> set.
	 * 
	 * @param atomIdentifier The identifier of the variable.
	 */
	public void makeFalse(String atomIdentifier)
	{
		trueVariables.remove(atomIdentifier);
	}

}
